package com.mm.ai.common.dto;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 统一返回体
 * @Author：tangnaichao
 * @Date：2024/10/15 19:30
 */
@Data
@Accessors(chain = true)
public class ResponseEntity<T> {
    public static final String INTERNAL_SERVER_ERROR = "500";

    /**
     * 是否成功
     */
    private boolean success = true;

    /**
     * 返回信息
     */
    private String resultMessage;

    /***
     * 返回code
     */
    private String resultCode = "0000";

    /**
     * 返回体
     */
    private T result;

    public static ResponseEntity ok() {
        return new ResponseEntity();
    }

    public static ResponseEntity ok(String msg) {
        ResponseEntity ResponseEntity = new ResponseEntity();
        ResponseEntity.setResultMessage(msg);
        return ResponseEntity;
    }

    public static <T> ResponseEntity<T> ok(T result) {
        ResponseEntity ResponseEntity = new ResponseEntity();
        ResponseEntity.setResult(result);
        return ResponseEntity;
    }

    public static ResponseEntity error(String msg) {
        ResponseEntity ResponseEntity = new ResponseEntity();
        ResponseEntity.setResultCode(INTERNAL_SERVER_ERROR);
        ResponseEntity.setSuccess(false);
        ResponseEntity.setResultMessage(msg);
        return ResponseEntity;
    }
}
